#include "seq_list.h"

//打印链表节点内容
void seq_print(seq_node* phead)
{
    seq_node* cur = phead;
    while(cur != NULL)
    {
        printf("%d ",cur->_data);
        cur = cur->_next;
    }
    printf("NULL\n");
}

//创建新的节点
seq_node* create_node(STLDataType x)
{
    seq_node* newnode = (seq_node*)malloc(sizeof(seq_node));
    newnode->_data = x;
    newnode->_next = NULL;
}

//查找指定位置的元素
seq_node* seq_find(seq_node* phead,STLDataType x)
{
    seq_node* cur = phead;
    while(cur)
    {
        if(cur->_data == x)
            return cur;
        cur = cur->_next;
    }
    return NULL;
}
//在pos位置前插入新节点
void seq_insert(seq_node** phead,seq_node* pos,STLDataType x)
{
    seq_node* cur = *phead;
    seq_node* newnode = create_node(x);
    if(pos == *phead)
    {
        newnode->_next = *phead;
        *phead = newnode;
    }
    else
    {
        while(cur->_next != pos)
            cur = cur->_next;
        cur->_next = newnode;
        newnode->_next = cur;
    }
}
//删除pos位的值
void seq_earse(seq_node** phead,seq_node* pos)
{
    seq_node* next = (*phead)->_next;
    if((*phead) == pos)
    {
        free(*phead);
        *phead = next;
    }
    else
    {
        seq_node* tail = *phead;
        while(tail->_next != pos)
        {
            tail = tail->_next;
        }
        tail->_next = pos->_next;
        free(pos);
        pos = NULL;
    }
}